package rush.rushcampus.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import rush.rushcampus.common.Result;
import rush.rushcampus.dto.CommmentDto;
import rush.rushcampus.service.ICommentService;
import rush.rushcampus.dto.CommentPageDto;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rush
 * @since 2024-06-11
 */
@Slf4j
@RestController
@RequestMapping("/comment")
@Api(tags = "评论管理")
public class CommmentController {
    @Autowired
    private ICommentService commentService;

    //提交评论
    @ApiOperation(value = "提交评论")
    @PostMapping("/add")
    public Result addComment(@RequestBody CommmentDto commmentDto) {
        commentService.addComment(commmentDto);
        return Result.success("添加成功");
    }
    //根据文章id查询评论（分页查询）
    @ApiOperation(value = "根据文章id查询评论（分页查询）：（不再使用）")
    @PostMapping("/list")
    public Result list(@RequestBody CommentPageDto commentPageDto){
        return Result.success(commentService.listComment(commentPageDto));
    }
    @ApiOperation(value = "根据文章id查询评论")
    @GetMapping("/listArticleComment")
    public Result listCopy(Long articleId , Integer commentBelongs){
        return Result.success(commentService.listArticleComment(articleId , commentBelongs));
    }
    //根据父评论id查询更多子评论
//    @ApiOperation(value = "根据父评论id查询更多子评论")
//    @GetMapping("/listChild")
//    public Result listChild(Long parentId , Integer isPrivate, Integer pageNum, Integer pageSize){
//        return Result.success(commentService.listComment(parentId , isPrivate , pageNum , pageSize));
//    }
    //根据id删除评论
    @Transactional
    @ApiOperation(value = "根据id删除评论")
    @DeleteMapping ("/delete")
    public Result delete(Long ArticleId){
        commentService.removeComment(ArticleId);
        return Result.success("删除成功");
    }

}
